package jmine.tec.persist.schema.impl.elements.type;

import jmine.tec.persist.schema.impl.elements.ColumnTypeElement;

import org.hibernate.type.Type;

import bancosys.tec.persist.hibernate.type.StaticIdEnum;

/**
 * Estratégia de tipo para enums java
 * 
 * @author lundberg
 */
public class StaticEnumTypeStrategy extends AbstractEnumTypeStrategy {

    /**
     * Obtém o valor utilizado para representar o elemento da enumeração no banco de dados.
     * 
     * @param <E> tipo de elemento
     * @param element element
     * @return valor
     */
    @Override
    protected <E extends Enum<?>> int getElementValue(E element) {
        return ((StaticIdEnum) element).getId();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean matches(ColumnTypeElement columnTypeElement, Type type) {
        return StaticIdEnum.class.isAssignableFrom(type.getReturnedClass()) && super.matches(columnTypeElement, type);
    }
}